import socket

# 创建一个UDP套接字
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# 设置超时时间
udp_socket.settimeout(5)

# 发送数据
udp_socket.sendto("你好，服务器！".encode(encoding="utf-8"), ("127.0.0.1", 8888))

# 接收响应
response, server_address = udp_socket.recvfrom(1024)
print("响应：", response.decode(encoding="utf-8"))

# 关闭套接字
udp_socket.close()